package array;

public class MinimumSizeSubarraySum209 {
    public int minSubArrayLen(int target, int[] nums) {
        int min = Integer.MAX_VALUE;
        int pre = 0;
        int last = 0;
        int sum = nums[pre];
        while (last != nums.length) {
            if (sum < target) {
                last++;
                sum = last==nums.length? sum: sum+nums[last];
                continue;
            }
            if (sum >= target) {
                int length = last - pre + 1;
                min = length > min ? min : length;
                sum = sum - nums[pre++];

            }
        }
        return min == Integer.MAX_VALUE ? 0 : min;
    }
}
